-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Vision cloud client snippets #751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
vision/cloud-client/snippets.py
Outdated
| import io | ||
| import os | ||
|
|
||
| # Imports the Google Cloud client library |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment isn't necessary. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed extraneous comments.
vision/cloud-client/snippets.py
Outdated
| # Loads the image into memory | ||
| with io.open(path, 'rb') as image_file: | ||
| content = image_file.read() | ||
| image = vision_client.image( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line doesn't need to be within the with context.
vision/cloud-client/snippets.py
Outdated
| image = vision_client.image( | ||
| content=content) | ||
|
|
||
| # Performs face detection on the image file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is obvious in context.
(Typically focus comments on why over what, especially if this isn't a quickstart)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed extraneous comments.
vision/cloud-client/snippets.py
Outdated
| # Performs face detection on the image file | ||
| faces = image.detect_faces() | ||
|
|
||
| print 'Faces:' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use print-as-a-function (print(...)) so that this work with Python 3. :)
vision/cloud-client/snippets.py
Outdated
|
|
||
| print 'Faces:' | ||
| for face in faces: | ||
| print 'anger', face.emotions.anger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use .format over multiple args to print.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
vision/cloud-client/snippets.py
Outdated
|
|
||
|
|
||
| def detect_faces_gcs(path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid initialisms unless its the primary focus of the sample, prefer detect_faces_cloud_storage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
vision/cloud-client/snippets.py
Outdated
| def detect_faces_gcs(path): | ||
| # Instantiates a client | ||
| vision_client = vision.Client() | ||
| image = vision_client.image(source_uri=path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this argument a path or is it a uri?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to URI where appropriate.
theacodes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there.
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """This application demonstrates how to perform basic operations with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: blank newline between license and docstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
vision/cloud-client/detect.py
Outdated
| anger=face.emotions.anger, | ||
| joy=face.emotions.joy, | ||
| surprise=face.emotions.surprise) | ||
| print('') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this strictly necessary or do you just like a blank newline at the end of the program output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entirely aesthetic, I'm happy to remove the empty print statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
up to you.
vision/cloud-client/detect.py
Outdated
| print('Safe search:') | ||
| for safe in safe_searches: | ||
| print('adult: {adult}\nmedical: {medical}\nspoofed: {spoofed}\n' + | ||
| 'violence: {violence}\n').format(adult=safe.adult, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh god, my eyes! No hanging indents, please:
print('oh god why did I make this string so long what is wrong with me.'.format(
arg1=something, arg2=something, ...)
vision/cloud-client/detect.py
Outdated
| safe_searches = image.detect_safe_search() | ||
| print('Safe search:') | ||
| for safe in safe_searches: | ||
| print('adult: {adult}\nmedical: {medical}\nspoofed: {spoofed}\n' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need newlines in your print, either make it separate print statements or use heredoc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I just removed the extraneous prints.
|
@dpebot merge when travis passes, pretty please. |
|
Okay! I'll merge when all statuses are green. |
|
@gguuss oh no, the linter thinks your main is too complex! Might need to bump it the config in https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/nox.py#L141 |
Adds snippet code for all 7 vision scenarios (GCS and local file) with the intention of longer-term sourcing all the snippets to the vision docs.